package com.cz.nongyetongv5.activity;


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.BeiJianDanWei;
import com.cz.nongyetongv5.bean.Plan;
import com.cz.nongyetongv5.bean.Town;
import com.cz.nongyetongv5.bean.User;
import com.cz.nongyetongv5.utils.AsyncClienter;
import com.cz.nongyetongv5.utils.Conf;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.ronri.ams.sample.MapItem;
import com.ronri.mapapi.clusterutil.clustering.ClusterManager;
import com.ronri.mapapi.location.service.LocationService;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class CheckActivity extends Activity implements OnClickListener, AMapLocationListener, BaiduMap.OnMapLoadedCallback {//声明进度条对话框
    private BaiduMap mBaiduMap;
    private MapStatus ms;
    private ClusterManager<MapItem> mClusterManager = null;
    // 是否创建
    private LocationService locService;

    /**
     * 用户对象
     */
    private User user = null;
    private Plan plan = null;
    private BeiJianDanWei ent = null;
    ProgressDialog m_pDialog = null;

    protected void show() {
        hide();
        m_pDialog = new ProgressDialog(this);
        m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        m_pDialog.setTitle("提示");

        m_pDialog.setMessage("正在加载请稍后...");

        m_pDialog.setCancelable(true);

        m_pDialog.show();
    }

    protected void hide() {
        if (m_pDialog != null) {
            try {
                m_pDialog.hide();
            } catch (java.lang.Exception e) {

            } finally {

                m_pDialog = null;
            }
        }
    }

    /**
     * 定位相关
     */
    public LocationClient mLocationClient = null;
    private BMapManager mBMapMan;
    private MapView mMapView = null;


    /**
     * 定位SDK的核心类
     */
    private LocationClient mLocClient;


    TextView btn_changeview;
    TextView btn_search;
    EditText inp_search;
    View list;
    LinearLayout listview;
    LinearLayout ent_detail;
    View ent_detail2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //		mBMapMan = new BMapManager(getApplication());
        //		mBMapMan.init(null);

        mBMapMan = new BMapManager();
        mBMapMan.init();

        setContentView(R.layout.v1_4_checkform);
        user = (User) getIntent().getSerializableExtra("user");
        ent = (BeiJianDanWei) getIntent().getSerializableExtra("ent");
        plan = (Plan) getIntent().getSerializableExtra("plan");
        list = this.findViewById(R.id.list);
        listview = (LinearLayout) this.findViewById(R.id.listview);
        ent_detail = (LinearLayout) this.findViewById(R.id.ent_detail);
        ent_detail.setTag(null);
        ent_detail2 = this.findViewById(R.id.ent_detail2);
        ent_detail2.setTag(null);
        ent_detail2.setOnClickListener(this);
        btn_changeview = (TextView) this.findViewById(R.id.btn_changeview);
        btn_changeview.setOnClickListener(this);
        btn_search = (TextView) this.findViewById(R.id.btn_search);
        inp_search = (EditText) this.findViewById(R.id.inp_search);
        btn_search.setOnClickListener(this);
        inp_search.setOnClickListener(this);
        findViewById(R.id.btnSure).setOnClickListener(this);
        findViewById(R.id.btnBack).setOnClickListener(this);
        mMapView = (MapView) findViewById(R.id.bmapView);
        //		mMapView.setBuiltInZoomControls(true);
        //		// 设置启用内置的缩放控件
        //		MapController mMapController = mMapView.getController();
        //		mMapController.setZoom(16);// 设置地图zoom级别

        //		mLocClient = new LocationClient(getApplicationContext());
        //		mLocClient.registerLocationListener(new );//注册定位监听接口

        //		LocationClientOption option = new LocationClientOption();
        //		option.setOpenGps(true); //打开GPRS
        //		option.setCoorType("bd09ll");//返回的定位结果是百度经纬度,默认值gcj02
        //		option.setPriority(LocationClientOption.GpsFirst); // 设置GPS优先
        //		option.setScanSpan(5000); //设置发起定位请求的间隔时间为5000ms
        //		option.disableCache(false);//禁止启用缓存定位
        //		mLocClient.setLocOption(option);  //设置定位参数
        //		show();
        //		mLocClient.start(); mBaiduMap = mMapView.getMap();
        mBaiduMap = mMapView.getMap();
        mBaiduMap.setOnMapLoadedCallback(this);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms));

        locService = InitApplication.locationService;
        LocationClientOption mOption = locService.getDefaultLocationClientOption();
        mOption.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
        mOption.setCoorType("bd09ll");
        locService.setLocationOption(mOption);
        locService.registerListener(listener);
        locService.start();

    }


    // 将经纬度转换成GeoPoint
    //	private GeoPoint transformToGeoP(double lat, double lng)
    //	{
    //		return new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    //	}

    List<BeiJianDanWei> ents = new ArrayList<BeiJianDanWei>();
    private double slat = 0;
    private double slng = 0;

    private void searchdata() {
        listview.removeAllViews();
        if (String.valueOf(inp_search.getText()).equals("")) {
            predata(false);
            return;
        }
        String code = user.getKnowRegion();
        if (plan != null)
            code = plan.getEntArea();
        String url = Conf.v1609_root + "/ent/keyword_map_search/region_code/" + code + "/limit/100/offset/0/username/" + user.getUsername() + "/from/1/keyword/" + inp_search.getText().toString();

        AsyncClienter.get(url, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject d) {
                super.onSuccess(statusCode, headers, d);

                JSONArray objents = d.optJSONArray("result");
                Log.d("debug", String.valueOf(objents));
                JSONObject c1 = new JSONObject();
                try {
                    c1.putOpt("id", "0");
                    c1.putOpt("latitude", slat);
                    c1.putOpt("longitude", slng);
                    if (objents == null)
                        objents = new JSONArray();
                    objents.put(c1);
                } catch (JSONException e) {

                }
                if (ents == null)
                    return;
                ents = new ArrayList<BeiJianDanWei>();
                for (int i = 0; i < objents.length(); i++) {
                    JSONObject c2 = objents.optJSONObject(i);
                    BeiJianDanWei b = new BeiJianDanWei();
                    b.setId(c2.optString("id"));
                    b.setName(c2.optString("name"));
                    b.setAddress(c2.optString("address"));
                    b.setCharge(c2.optString("charge"));
                    b.setTel(c2.optString("contact"));
                    b.setD(c2.optString("d"));
                    b.setKind(c2.optInt("kind"));
                    b.setLatitude(c2.optDouble("latitude"));
                    b.setLongitude(c2.optDouble("longitude"));
                    b.setCode(c2.optString("region_code"));
                    ents.add(b);
                }
                if (viewType.equals("map")) {
                    refmap();
                } else
                    reflist();

            }

            @Override
            public void onFailure(int statusCode, Header[] headers,
                                  Throwable error, JSONObject data) {
                super.onFailure(statusCode, headers, error, data);
                Toast.makeText(CheckActivity.this, "服务器异常,请稍后重试", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onStart() {
                super.onStart();
                show();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                hide();
            }

        });


    }

    boolean isf = true;

    private void predata(final boolean try2) {


        String url = Conf.v160918_pretask + "ajax/dataMobmap.php?lat=" + slat + "&lng=" + slng + "&code=" + user.getKnowRegion();

        Log.d("debug", url);
        AsyncClienter.post(url, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject d) {
                super.onSuccess(statusCode, headers, d);

                Log.d("debug", String.valueOf(d));
                JSONArray objents = d.optJSONArray("data");
                //				mMapView.getController().setCenter(transformToGeoP(slat,slng));

                JSONObject c1 = new JSONObject();
                try {
                    c1.putOpt("latitude", slat);
                    c1.putOpt("longitude", slng);
                    c1.putOpt("id", "0");

                    objents.put(c1);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (ents == null)
                    return;
                ents = new ArrayList<BeiJianDanWei>();
                for (int i = 0; i < objents.length(); i++) {
                    JSONObject c2 = objents.optJSONObject(i);
                    BeiJianDanWei b = new BeiJianDanWei();
                    b.setId(c2.optString("id"));
                    b.setName(c2.optString("name"));
                    b.setAddress(c2.optString("address"));
                    b.setCharge(c2.optString("charge"));

                    if (c2.optString("tel").equals("")) {
                        b.setTel(c2.optString("mobile"));
                    } else
                        b.setTel(c2.optString("tel"));
                    b.setCode(c2.optString("region_code"));
                    b.setKind(c2.optInt("kind"));
                    b.setD(c2.optString("d"));
                    b.setLatitude(c2.optDouble("latitude"));
                    b.setLongitude(c2.optDouble("longitude"));
                    ents.add(b);

                }

                refmap();

            }

            @Override
            public void onFailure(int statusCode, Header[] headers,
                                  Throwable error, JSONObject data) {
                super.onFailure(statusCode, headers, error, data);
                if (try2) {
                    Toast.makeText(CheckActivity.this, "服务器繁忙,正在重试", Toast.LENGTH_SHORT).show();
                    predata(false);
                } else {
                    Toast.makeText(CheckActivity.this, "服务器异常,请稍后重试", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onStart() {
                super.onStart();
                show();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                hide();
            }

        });


    }

    private double djl(double lat_a, double lng_a, double lat_b, double lng_b) {
        double pk = 180 / 3.14169;
        double a1 = lat_a / pk;
        double a2 = lng_a / pk;
        double b1 = lat_b / pk;
        double b2 = lng_b / pk;
        double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
        double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
        double t3 = Math.sin(a1) * Math.sin(b1);
        double tt = Math.acos(t1 + t2 + t3);
        return 6366000 * tt;
    }

    private void reflist() {
        ent_detail.setVisibility(View.GONE);
        listview.removeAllViews();
        for (int i = 0; i < ents.size(); i++) {
            BeiJianDanWei de = ents.get(i);
            if (!de.getId().equals("0")) {
                View ent_detail = getLayoutInflater().inflate(R.layout.v1_4_ent_item, null, false);
                ent_detail.setTag(de);
                TextView tit = (TextView) ent_detail.findViewById(R.id.txt_title);
                TextView txt_user = (TextView) ent_detail.findViewById(R.id.txt_user);
                TextView txt_kind = (TextView) ent_detail.findViewById(R.id.txt_kind);
                TextView txt_d = (TextView) ent_detail.findViewById(R.id.txt_d);
                tit.setText(de.getName());
                txt_user.setText("负责人:" + de.getCharge() + "  " + de.getTel());
                txt_kind.setText(de.getKindStr());
                if (!String.valueOf(de.getD()).equals(""))
                    txt_d.setText("相距" + de.getD() + "米");
                else {
                    double df = djl(slat, slng, de.getLatitude(), de.getLongitude());
                    if (df > 0 && df < 10000) {
                        DecimalFormat df2 = new DecimalFormat("0.0");
                        txt_d.setText("相距" + df2.format(df) + "米");
                    }
                }


                ent_detail.setTag(de);
                ent_detail.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("ent", (BeiJianDanWei) arg0.getTag());
                        bundle.putSerializable("town", null);
                        intent.putExtra("data", bundle);
                        intent.putExtra("type", "1");
                        setResult(
                                ChanPinJianCePlanRecordActivity.TO_SELENTS,
                                intent);
                        finish();

                    }
                });
                listview.addView(ent_detail);
            }
        }
    }

    private void refmap() {
        ent_detail.setVisibility(View.GONE);
        Drawable mark = getResources().getDrawable(R.drawable.arrow);
        //		MyOverlay  mOverlay = new MyOverlay(mark, mMapView);
        //		mMapView.getOverlays().clear();
        //		for(int i=0;i<ents.size();i++){
        //			BeiJianDanWei b=ents.get(i);
        //			GeoPoint p1 = transformToGeoP(b.getLatitude(),b.getLongitude());
        //			Drawable mark1= getResources().getDrawable(R.drawable.point_me);
        //			if(b.getId().equals("0")) mark1= getResources().getDrawable(R.drawable.point_ent);
        //			OverlayItem item1 =new OverlayItem(p1,"item"+i,"item"+i);
        //			item1.setMarker(mark1);
        //			mOverlay.addItem(item1);
        //
        //		}
        //		mMapView.getOverlays().add(mOverlay);
        //		mMapView.refresh();
        //

        //新版用法
        //		//定义Maker坐标点


        for (int i = 0; i < ents.size(); i++) {
            BeiJianDanWei b = ents.get(i);
            if (b.getId().equals("0")) {
                LatLng point = new LatLng(b.getLatitude(), b.getLongitude());
                //构建Marker图标
                BitmapDescriptor bitmap = BitmapDescriptorFactory
                        .fromResource(R.drawable.point_ent);
                //构建MarkerOption，用于在地图上添加Marker
                OverlayOptions option = new MarkerOptions()
                        .position(point)
                        .icon(bitmap);
                mBaiduMap.clear();
                //在地图上添加Marker，并显示
                mBaiduMap.addOverlay(option);
                mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(point));
            }
        }


    }

    @Override
    public void onMapLoaded() {
        ms = new MapStatus.Builder().zoom(19).build();
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(ms));
    }

    //	public class MyOverlay extends ItemizedOverlay<OverlayItem> {
    //		//用MapView构造ItemizedOverlay
    //		public MyOverlay(Drawable mark, MapView mapView) {
    //			super(mark, mapView);
    //		}
    //
    //		protected boolean onTap(int index) {
    //
    //			BeiJianDanWei de = ents.get(index);
    //			if (de.getId().equals("0")) {
    //				return true;
    //			}
    //			ent_detail.setVisibility(View.VISIBLE);
    //
    //			ent_detail2.setTag(de);
    //			TextView tit = (TextView) ent_detail.findViewById(R.id.txt_title);
    //			TextView txt_user = (TextView) ent_detail.findViewById(R.id.txt_user);
    //			TextView txt_kind = (TextView) ent_detail.findViewById(R.id.txt_kind);
    //			TextView txt_d = (TextView) ent_detail.findViewById(R.id.txt_d);
    //			tit.setText(de.getName());
    //			txt_user.setText("负责人:" + de.getCharge() + "  " + de.getTel());
    //			txt_kind.setText(de.getKindStr());
    //			txt_d.setText("");
    //			if (!String.valueOf(de.getD()).equals(""))
    //				txt_d.setText("相距" + de.getD() + "米");
    //			double df = djl(slat, slng, de.getLatitude(), de.getLongitude());
    //			if (df > 0 && df < 10000) {
    //				DecimalFormat df2 = new DecimalFormat("0.0");
    //				txt_d.setText("相距" + df2.format(df) + "米");
    //			}
    //			return true;
    //		}
    //
    //		public boolean onTap(GeoPoint pt, MapView mapView) {
    //			ent_detail.setVisibility(View.GONE);
    //			return false;
    //		}
    //	}


    //	private void addOverlay(ArrayList<MapInfo> mapInfos) {
    //		//清空地图
    //		mBaiduMap.clear();
    //		//创建marker的显示图标
    //		BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
    //		LatLng latLng = null;
    //		Marker marker;
    //		OverlayOptions options;
    //		for (MapInfo mapInfo : mapInfos) {
    //			//获取经纬度
    //			latLng = new LatLng(mapInfo.getLatitude(), mapInfo.getLongitude());
    //			//设置marker
    //			options = new MarkerOptions()
    //					.position(latLng)//设置位置
    //					.icon(bitmap)//设置图标样式
    //					.zIndex(9) // 设置marker所在层级
    //					.draggable(true); // 设置手势拖拽;
    //			//添加marker
    //			marker = (Marker) mBaiduMap.addOverlay(options);
    //			//使用marker携带info信息，当点击事件的时候可以通过marker获得info信息
    //			Bundle bundle = new Bundle();
    //			//info必须实现序列化接口
    //			bundle.putSerializable("mapInfo", mapInfo);
    //			marker.setExtraInfo(bundle);
    //		}
    //		//将地图显示在最后一个marker的位置
    //		MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng);
    //		mBaiduMap.setMapStatus(msu);
    //
    //		mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
    //			@Override
    //			public boolean onMarkerClick(Marker marker) {
    //				Bundle bundle = marker.getExtraInfo();
    //				MapInfo mapInfo = (MapInfo) bundle.getSerializable("mapInfo");
    //				TextView tv = new TextView(EntUpdateActivity.this);
    //				tv.setBackgroundColor(Color.GRAY);
    //				tv.setPadding(20, 10, 20, 20);
    //				tv.setGravity(Gravity.CENTER);
    //				tv.setTextColor(android.graphics.Color.WHITE);
    //				tv.setText(mapInfo.getName() + "\n" + mapInfo.getAddress());
    //				LatLng latLng = new LatLng(mapInfo.getLatitude(), mapInfo.getLongitude());
    //				mInfoWindow = new InfoWindow(BitmapDescriptorFactory.fromView(tv), latLng, -47, new InfoWindow.OnInfoWindowClickListener() {
    //					@Override
    //					public void onInfoWindowClick() {
    //						mBaiduMap.hideInfoWindow();
    //					}
    //				});
    //				mBaiduMap.showInfoWindow(mInfoWindow);
    //				return true;
    //			}
    //		});
    //	}
    /***
     * 定位请求回调函数,这里面会得到定位信息
     *
     * @param bdLocation
     */
    BDLocationListener listener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null) {
                Log.d("debug", "没有结果");
                return;
            } else {
                Log.d("debug", String.valueOf(location.getLatitude()));
                slat = location.getLatitude();
                slng = location.getLongitude();
                //  	      slat=31.823974;
                //  	      slng=119.511498;
                if (isf) {
                    isf = false;
                    locService.stop();
                    locService.unregisterListener(listener);
                    //                    mLocClient.stop();
                    predata(true);


                }
            }
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }
    };

    //
    //	public class BDLocationListenerImpl implements BDLocationListener {
    //
    //		/**
    //		 * 接收异步返回的定位结果，参数是BDLocation类型参数
    //		 */
    //		@Override
    //		public void onReceiveLocation(BDLocation location) {
    //
    //			if (location == null) {
    //				Log.d("debug","没有结果");
    //				return;
    //			}  else{
    //				Log.d("debug",String.valueOf(location.getLatitude()));
    //				slat=location.getLatitude();
    //				slng=location.getLongitude();
    //				//  	      slat=31.823974;
    //				//  	      slng=119.511498;
    //				if(isf){
    //					isf=false;
    //					mLocClient.stop();
    //					predata(true);
    //
    //
    //				}
    //			}
    //		}
    //
    //		@Override
    //		public void onReceivePoi(BDLocation bdLocation) {
    //
    //		}
    //
    //
    //	}

    public static final int TO_SELENTS = 66;

    private String viewType = "map";

    @Override
    public void onClick(View arg0) {
        if (arg0.getId() == R.id.btn_changeview) {
            btn_changeview.setText(viewType.equals("map") ? "查看地图" : "查看列表");
            if (viewType.equals("map")) {
                list.setVisibility(View.VISIBLE);
                mMapView.setVisibility(View.GONE);
                viewType = "list";
                reflist();
            } else {
                list.setVisibility(View.GONE);
                mMapView.setVisibility(View.VISIBLE);
                viewType = "map";
                refmap();
            }
        } else if (arg0.getId() == R.id.btn_search) {
            searchdata();
        } else if (arg0.getId() == R.id.btnSure) {
            Intent intent = new Intent(CheckActivity.this, ChanPinJianCeSelEntActivity.class);
            intent.putExtra("user", user);
            intent.putExtra("ent", ent);
            startActivityForResult(intent, TO_SELENTS);
        } else if (arg0.getId() == R.id.btnBack) {
            finish();
        } else if (arg0.getId() == R.id.ent_detail2) {
            //确认
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("ent", (BeiJianDanWei) arg0.getTag());
            bundle.putSerializable("town", null);
            intent.putExtra("data", bundle);
            intent.putExtra("type", "1");
            setResult(
                    ChanPinJianCePlanRecordActivity.TO_SELENTS,
                    intent);
            finish();

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == TO_SELENTS) {
            if (data != null) {
                String type = data.getStringExtra("type");
                if (type.equals("1")) {
                    Bundle iBundle = data.getBundleExtra("data");
                    BeiJianDanWei bjdw = (BeiJianDanWei) iBundle.get("ent");

                    Object[] towns = (Object[]) iBundle.get("towns");
                    Town[] tow = new Town[4];
                    for (int i = 0; i < towns.length; i++) {
                        tow[i] = (Town) towns[i];
                    }
                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("ent", bjdw);
                    if (plan != null)
                        bundle.putSerializable("towns", tow);
                    intent.putExtra("data", bundle);
                    intent.putExtra("type", "1");
                    setResult(ChanPinJianCePlanRecordActivity.TO_SELENTS,
                            intent);
                    finish();

                }
            }
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onLocationChanged(Location arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onLocationChanged(AMapLocation arg0) {
        if (arg0 != null) {

            final double latitude = (double) (Math.round(arg0.getLatitude() * 1000000) / 1000000.0);

            // 精度
            final double longitude = (double) (Math.round(arg0.getLongitude() * 1000000) / 1000000.0);
            Log.d("debug", latitude + "");

        }
    }

    /**
     * 高德地图的定位属性
     */
    private LocationManagerProxy mAMapLocManager = null;
    /**
     * 高德地图的定位信息对象
     */
    //private AMapLocation location = null;
    //@Override
    //protected void onDestroy() {
    //
    //	InitApplication initApplication = (InitApplication) getApplicationContext();
    //
    //	initApplication.getActivities().remove(this);
    //
    //	if (mAMapLocManager != null) {
    //		mAMapLocManager.removeUpdates(this);
    //		mAMapLocManager.destory();
    //	}
    //	mAMapLocManager = null;
    //	super.onDestroy();
    //}
    //
    //@Override
    //protected void onResume() {
    //	super.onResume();
    //
    //	/*
    //	 * 初始化高德地图的定位对象
    //	 */
    //	mAMapLocManager = LocationManagerProxy.getInstance(this);
    //
    //	mAMapLocManager.requestLocationUpdates(
    //			LocationProviderProxy.AMapNetwork, 1500, 10, this);
    //
    //}
    //
    //@Override
    //protected void onPause() {
    //	super.onPause();
    //	if (mAMapLocManager != null) {
    //		mAMapLocManager.removeUpdates(this);
    //		mAMapLocManager.destory();
    //	}
    //	mAMapLocManager = null;
    //
    //}

}